import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
/**Clase derivada de servidor Empleada par aenviar mensajes a un cliente
 * 
 * @author Francisco
 *
 */
public class ServerWrite extends Thread {

	ServerSocket ss;
	Socket cliente;
	Monitor monitor;

	public ServerWrite(ServerSocket ss, Socket cliente, Monitor monitor) {
		this.ss = ss;
		this.cliente = cliente;
		this.monitor = monitor;
	}
	@Override
	public void run() {
		try {
			PrintWriter salidaAlCliente = new PrintWriter(
					cliente.getOutputStream(), true);
			int cont = 0;
			do {
				salidaAlCliente.println("Escribo" + cont);
				cont++;
				Thread.sleep(2000);
			} while (monitor.isEscribir());
			salidaAlCliente.close();
			monitor.setCanWrite(true);
			cliente.close();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}
}
